<template>
	<view class="container">
		<view class="top" :style="{borderRadius:isAll ? '0 0 20rpx 20rpx' : '0',}">
			<view class="search-box">
				<headerSearch bgColor="#F6F6F6" placeholder="搜索" @searchBlur="searchBlur">
					<view class="r-box" slot="right" @click="toRecord">
						<image :src="$img_path('/pagesRegion/5.png')" mode="widthFix"></image>
						<text>申请记录</text>
					</view>
				</headerSearch>
			</view>
			
			<view class="classify">
				<view class="a-box">
					<view class="title" v-if="isAll">
						全部分类
					</view>
					<view :class="['c-box', isAll ? 'column' : 'row']">
						<view class="item" v-for="(item,i) in classifyList" :key="i" @click="classifyChange(item)">
							<view class="img">
								<image :src="$img_base_url(item.image)" mode="aspectFill"></image>
							</view>
							<text class="one-row">{{item.label}}</text>
						</view>
					</view>
					
					<view class="close-all" v-if="isAll" @click="isAll = false">
						<text>点击收起</text>
						<image :src="$img_path('/pagesMine/56.png')" mode="widthFix"></image>
					</view>
				</view>
				<image class="open-all" v-if="!isAll" @click="isAll = true" :src="$img_path('/pagesRegion/6.png')" mode="widthFix"></image>
			</view>
			
			<view class="bg-black" v-if="isAll"></view>
		</view>
		
		<view class="list">
			<view class="item" v-for="(item,i) in goodsList" :key="i" @click="toDetail(item)">
				<image :src="$img_base_url(item.image)" mode="aspectFill"></image>
				<view class="info">
					<view class="name one-row">
						{{item.name}}
					</view>
					<view class="text one-row">
						{{item.shopname}}
					</view>
					<view class="price">
						<view class="p">
							<text>¥</text> {{item.price}}
						</view>
						<view class="n">
							销量：{{item.salenums}}
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { getShopCategoryList, getServiceGoodsList } from '@/utils/api/serviceApi.js'
	import headerSearch from '@/components/header-search/header-search.vue'
	export default {
		components:{
			headerSearch,
		},
		data() {
			return {
				isAll:false,
				classifyList:[],
				
				goodsList:[],
				page:1,
				name:'',
				category_id:''
			};
		},
		onLoad() {
			this.getShopCategoryList()
			this.getServiceGoodsList()
		},
		methods:{
			searchBlur(data){
				let value = data.detail.value
				this.name = value
				this.getServiceGoodsList()
			},
			
			// 分类
			getShopCategoryList(){
				getShopCategoryList().then(res=>{
					this.classifyList = res.data
				})
			},
			// 服务列表
			getServiceGoodsList(){
				getServiceGoodsList({
					page:this.page,
					name:this.name,
					category_id:this.category_id
				}).then(res=>{
					this.goodsList = res.data
				})
			},
			
			// 分类
			classifyChange(data){
				this.isAll = false
				this.category_id = data.id
				this.getServiceGoodsList()
			},
			
			toDetail(data){
				uni.navigateTo({
					url:`/pagesRegion/serviceManagement/detail?id=${data.id}`
				})
			},
			toRecord(){
				uni.navigateTo({
					url:'/pagesRegion/serviceManagement/record'
				})
			}
		}
	}
</script>
<style>
	page{
		background-color: #FFFFFF;
	}
</style>
<style lang="scss" scoped>
.container{
	.top{
		position: sticky;
		top: 0;
		left: 0;
		right: 0;
		width: 100%;
		background-color: #FFFFFF;
		.search-box{
			padding: 14rpx 22rpx 0;
			box-sizing: border-box;
			position: relative;
			z-index: 3;
			header-search{
				height: 84rpx;
			}
			.r-box{
				padding: 0 16rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				image{
					width: 45rpx;
					height: 48rpx;
				}
				text{
					font-weight: bold;
					font-size: 16rpx;
					color: #000000;
					line-height: 22rpx;
					margin-top: 4rpx;
				}
			}
		}
		.classify{
			padding: 48rpx 0rpx 0;
			box-sizing: border-box;
			position: relative;
			background-color: #FFFFFF;
			z-index: 4;
			// top: 98rpx;
			width: 100%;
			height: 190rpx;
			overflow: initial;
			.a-box{
				padding: 0 30rpx;
				background-color: #FFFFFF;
				border-radius: 20rpx !important;
				box-sizing: border-box;
				.title{
					font-weight: bold;
					font-size: 32rpx;
					color: #000000;
					line-height: 44rpx;
				}
				.c-box{
					&.row{
						overflow-x: auto;
						white-space: nowrap;
						.item{
							display: inline-block;
							&:not(:last-child){
								margin-right: 48rpx;
							}
							&:last-child{
								margin-right: 42rpx;
							}
							.img{
								width: 100rpx;
								height: 100rpx;
								margin: 0 auto;
								image{
									width: 100%;
									height: 100%;
								}
							}
							&>text{
								font-weight: 400;
								font-size: 30rpx;
								color: #333333;
								line-height: 34rpx;
								margin-top: 12rpx;
								// width: 100rpx;
								display: inline-block;
								text-align: center;
							}
						}
					}
					&.column{
						display: flex;
						flex-wrap: wrap;
						.item{
							padding: 0 32rpx;
							box-sizing: border-box;
							&:not(:nth-child(4n)){
								margin-right: 12rpx;
							}
							margin-top: 40rpx;
							.img{
								width: 100rpx;
								height: 100rpx;
								margin: 0 auto;
								image{
									width: 100%;
									height: 100%;
								}
							}
							&>text{
								font-weight: 400;
								font-size: 24rpx;
								color: #333333;
								line-height: 34rpx;
								margin-top: 12rpx;
								width: 100rpx;
								display: inline-block;
								text-align: center;
							}
						}
					}
				}
				.close-all{
					padding: 44rpx 0 52rpx;
					box-sizing: border-box;
					display: flex;
					align-items: center;
					justify-content: center;
					text{
						font-weight: 400;
						font-size: 28rpx;
						color: #000000;
						line-height: 40rpx;
					}
					image{
						width: 19rpx;
						height: 11rpx;
						margin-left: 16rpx;
					}
				}
			}
			
			.open-all{
				width: 72rpx;
				height: 148rpx;
				position: absolute;
				top: 20rpx;
				right: 0;
			}
		}
		
		.bg-black{
			position: fixed;
			width: 100vw;
			height: 100vh;
			background-color: rgba(0, 0, 0, 0.4);
			z-index: 2;
		}
	}
	
	.list{
		display: flex;
		justify-content: space-between;
		padding: 0 22rpx;
		box-sizing: border-box;
		flex-wrap: wrap;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
		.item{
			width: 344rpx;
			margin-top: 42rpx;
			image{
				width: 100%;
				height: 246rpx;
				border-radius: 20rpx;
			}
			.info{
				.name{
					font-weight: bold;
					font-size: 32rpx;
					color: #333333;
					line-height: 44rpx;
					margin-top: 14rpx;
				}
				.text{
					font-weight: 400;
					font-size: 24rpx;
					color: #333333;
					line-height: 34rpx;
					margin-top: 8rpx;
				}
				.price{
					display: flex;
					align-items: center;
					justify-content: space-between;
					.p{
						font-weight: 900;
						font-size: 42rpx;
						color: #FF2E2E;
						line-height: 58rpx;
						text{
							font-size: 34rpx;
						}
					}
					.n{
						font-weight: 400;
						font-size: 24rpx;
						color: #999999;
						line-height: 34rpx;
					}
				}
			}
		}
	}
}
</style>
